﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Drawing;
using AudioPlayer.GUI.Theme;

namespace AudioPlayer.GUI.Renderer {
	/// <summary>
	/// Renderer used to render menuStrip controls.
	/// </summary>
	internal class MenuRenderer : ToolStripProfessionalRenderer {
		#region Variables

		#endregion
		#region Constructor
		public MenuRenderer() {

		}
		#endregion
		#region Override
		protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e) {
			//base.OnRenderToolStripBackground(e);
			LinearGradientBrush brushBg = new LinearGradientBrush(e.AffectedBounds,
				ThemeManager.ActiveColorTable.MenuStripBackground1,
				ThemeManager.ActiveColorTable.MenuStripBackground2,
				LinearGradientMode.Horizontal);
			e.Graphics.FillRectangle(brushBg, e.AffectedBounds);

			//Dispose
			brushBg.Dispose();
		}
		protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs e) {
			Rectangle rect = new Rectangle(e.Item.ContentRectangle.X,e.Item.ContentRectangle.Y,e.Item.ContentRectangle.Width,e.Item.ContentRectangle.Height+2);
			if (!e.Item.IsOnDropDown) {
				if (e.Item.Selected) {
					LinearGradientBrush brushDown = new LinearGradientBrush(rect,
						ThemeManager.ActiveColorTable.MenuStripBackground1,
						ThemeManager.ActiveColorTable.ToolStripBackground2,
						LinearGradientMode.Vertical);
					Pen penBorder = new Pen(brushDown);
					//Draw background
					e.Graphics.FillRectangle(brushDown, rect);
					//Draw border
					e.Graphics.DrawLine(penBorder, new Point(rect.Left, rect.Top), new Point(rect.Left, rect.Bottom));
					//Clean up
					penBorder.Dispose();
					brushDown.Dispose();
				}
			} else {
				base.OnRenderMenuItemBackground(e);
			}
		}
		#endregion
	}
}
